<?php

require_once 'Pipes/Exception.php';
require_once 'Pipes/Xml/Node.php';
require_once 'PipesImpl/Visitor.php';

class Pipes_Xml_PipesNsCleaner implements PipesImpl_Visitor
{
	public function visit(PipesImpl_Visitable $visitable) {
		if (!$visitable instanceof Pipes_Xml_Node) {
			throw new Pipes_Exception('ERR_INVALID_VISITOR');
		}
		
		if ($visitable->hasAttributes()) {
			foreach ($visitable->attributes as $attribute) {
				if (substr($attribute->nodeName, 0, 6) == 'pipes:') {
					$visitable->removeAttributeNode($attribute);
				}
			}
		}
		
		if ($visitable->hasChildNodes()) {
			foreach ($visitable->childNodes as $childNode) {
				$childNode->accept($this);
			}
		}
	}
}